package com.cskaoyan.controller.wxcontroller;

import com.cskaoyan.bean.po.MarketOrderGoods;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.chaosbean.vxorder.bo.CommentBO;
import com.cskaoyan.bean.chaosbean.vxorder.bo.SubmitBO;
import com.cskaoyan.bean.chaosbean.vxorder.vo.ListVO;
import com.cskaoyan.bean.chaosbean.vxorder.vo.VXDetailVO;
import com.cskaoyan.service.adminservice.CommentService;
import com.cskaoyan.service.adminservice.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author jackX
 * @datetime 2022/12/31 20:11
 * @description: TODO:
 */
@RestController
@RequestMapping("wx/order")
public class OrderWeChatController {
    @Autowired
    OrderService orderService;
    @Autowired
    CommentService commentService;

    /**
     * 微信我的订单页面的显示分页
     *
     * @return
     */
    //http://localhost:8083/wx/order/list?showType=0&page=1&limit=10
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info, Integer showType) {
        ListVO vo = orderService.listOrder(info, showType);
        return BaseRespVo.okYa(vo);
    }

    /**
     * 微信我的订单详情页面
     *
     * @param orderId
     * @return
     */
    //http://localhost:8083/wx/order/detail?orderId=1
    @RequestMapping("detail")
    public BaseRespVo detail(Integer orderId) {
        VXDetailVO vo = orderService.vxOrderDetail(orderId);
        return BaseRespVo.okYa(vo);
    }

    /**
     * 微信我的订单申请退款界面
     */
    //http://182.92.235.201:8083/wx/order/refund
    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody Map map) {
        Integer id = (Integer) map.get("orderId");
        orderService.vxUpdateStatusRefund(id);
        return BaseRespVo.ok();
    }

    /**
     * 微信我的订单申请退款界面
     */
    //http://182.92.235.201:8083/wx/order/confirm
    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody Map map) {
        Integer id = (Integer) map.get("orderId");
        orderService.vxUpdateStatusConfirmById(id);
        return BaseRespVo.ok();
    }

    /**
     * 微信商我的订单评价页面
     *
     * @param orderId
     * @param goodsId
     * @return
     */
    //http://localhost:8083/wx/order/goods?orderId=1&goodsId=1057036
    @RequestMapping("goods")
    public BaseRespVo goods(Integer orderId, Integer goodsId) {
        MarketOrderGoods commentVO = orderService.vxOrderGoodsComment(orderId, goodsId);
        return BaseRespVo.okYa(commentVO);
    }

    /**
     * 微信我的订单提交评价
     *
     * @param comBO
     * @return
     */
    //http://182.92.235.201:8083/wx/order/comment
    @RequestMapping("comment")
    public BaseRespVo comment(@RequestBody CommentBO comBO) {
        commentService.addComment(comBO);
        return BaseRespVo.ok();
    }

    //http://182.92.235.201:8083/wx/order/submit
    @PostMapping("submit")
    public BaseRespVo submit(@RequestBody SubmitBO bo) {
        System.out.println("bo = " + bo);
        return BaseRespVo.ok();
    }

    //http://localhost:8083/wx/order/cancel
    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody Map map) {
        Integer id = (Integer) map.get("orderId");
        orderService.vxUpdateStatus(id);
        return BaseRespVo.ok();
    }

    //http://182.92.235.201:8083/wx/order/delete
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        Integer id = (Integer) map.get("orderId");
        orderService.deleteOrder(id);
        return BaseRespVo.ok();
    }
}
